
//
// 120305 - AH - Created.
//

package org.soekrat.gui.swing.dictionary;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.soekrat.gui.swing.TestFrame;

/**
 * <p>
 *   Demo/test program for
 *   {@link DictionaryAutoCompleteReplaceTextView} and
 *   {@link DictionaryWordList}.
 * </p>
 * @author Arne Halvorsen (AH)
 */
@SuppressWarnings("serial")
public final class DictionaryDemo extends JPanel
{
  private DictionaryAutoCompleteReplaceTextView m_dactf=
    new DictionaryAutoCompleteReplaceTextView();
  
  private DictionaryWordList m_dwl=
    new DictionaryWordList(m_dactf.getDictionary());
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public DictionaryDemo()
  {
    setLayout(new BorderLayout());
    
    JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    sp.setLeftComponent(m_dactf);
    sp.setRightComponent(m_dwl);
    add(sp, BorderLayout.CENTER);
    
    m_dactf.addChangeListener
    (
      new ChangeListener() 
      {
        public void stateChanged(ChangeEvent e)
        {
          String word=m_dactf.getText();
          m_dwl.addWord(word);
          m_dactf.setText("");
        }
      }
    );
  }
  
  public static void main(String[] args)
  {
    TestFrame.show(new DictionaryDemo());  
  }
  
}
